<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function cleartbox()
{	
	document.getElementById("Sea_P_Id").innerHTML="";
}
</script>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","p_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{ 
document.p_name.Prog_Name.value=val;
document.getElementById("List").innerHTML="";
}
</script>
<script type="text/javascript">
function getRes(hin)
{
	var xmlhttp;    
if (hin=="")
  {
  document.getElementById("Sea_P_Id").innerHTML='<font class="err"><img src="../images/alert.jpg" width="12" height="12"/> Please enter the Programme name!</font>';
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("Sea_P_Id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getids.php?q="+hin,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
require_once '../Login/databaseconnection.php';
if(!loggedin())
{
require_once '../index.php';
}
   
   else
   {
   $action=$_GET['action'];
   if($_GET['action']=="programme")
   {
   $P_Id=$_GET['p'];
}
 if($_GET['action']=="school")
   { 
$P_Id=$_GET['p'];   
   $S_Id=$_GET['s'];   
}
 if($_GET['action']=="year")
   {  
   $P_Id=$_GET['p'];
   $year=$_GET['y'];    
   }
    if($_GET['action']=="programmewithschoolandyear")
   {
   $P_Id=$_GET['p'];
   $S_Id=$_GET['s'];   
   $year=$_GET['y'];   
   }
if($action=="programme")
   {
  	   if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
 $Own_School_Id=$rowsch['School_Id'];
 $Exc_que="SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id'";
   	$result=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result for you,Please check your input and try again!";
   }
   }
   if(mysql_num_rows($get_Sch)==0)
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM programmes WHERE Programme_Id='$P_Id'";
	   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
	   }
	   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	   }
	   if($action=="school")
   {
	   if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
 $Own_School_Id=$rowsch['School_Id'];
 if($S_Id==$Own_School_Id)
	{
	$Exc_que="SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id'";
   	$result=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result for you,Please check your input and try again!";
   }
   	}
	else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND School_Id='$S_Id'";
	   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND School_Id='$S_Id'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
	   }
	   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	   }
	   if($action=="year")
   {
	   if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
 $Own_School_Id=$rowsch['School_Id'];
 $Exc_que="SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id' AND Year='$year'";
   	$result=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id' AND Year='$year'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result for you,Please check your input and try again!";
   }
   }
		 if(mysql_num_rows($get_Sch)==0)
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year'";
	   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
	   }
	   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	   }
	     if($action=="programmewithschoolandyear")
   {
	   if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
    
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
 $Own_School_Id=$rowsch['School_Id'];
 if($S_Id==$Own_School_Id)
	{
	$Exc_que="SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id' AND Year='$year'";
   	$result=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id' AND Programme_Id='$P_Id' AND Year='$year'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result for you,Please check your input and try again!";
   }
   }
   	else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$Exc_que="SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year' AND School_Id='$S_Id'";
	   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year' AND School_Id='$S_Id'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
	   }
	   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	   }
   ?>
<?php

include_once "../header2.php";


?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<div id="lefttable">
<table width="530" border="0" class="tablefontv">
<tr><td width="47" height="43" class="err">
<?php
if(isset($_SESSION['errornotallo']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornotallo'];
		unset($_SESSION['errornotallo']);
	}
if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
?>
</td></tr></table>
 <table width="530" border="0" class="tablefontv">
  <tr><form name="p_name">
  <td width="47" height="43"></td>
      <td width="131">Programme Name:</td>
      <td width="149">
	  <?php
	  $pnam=mysql_query("SELECT * FROM programme WHERE Programme_Id='$P_Id'");
	  if($rop=mysql_fetch_array($pnam))
	  {
	  $P_name=$rop['Programme_Name'];
	  }
	  echo "<input type='text' id='Prog_Name' name='Prog_Name' onKeyUp='showHint(this.value)' value='$P_name' onClick='cleartbox()'/>";
	  ?>
	  </td>
      <td width="33"><input type="button" class="searchid" onClick="getRes(Prog_Name.value)"></td>
      <td width="148">
     </td></form>
  </tr>
  <tr>
  <td>
  </td>
  <td>
  </td><td>
 <div class="suggestionListPro" id="List"></div> </td>
 <td>
 </td>
 <td></td>
  </tr></table>
  <br/>
   <div id="Sea_P_Id"> 
  <?php
 	  if($result)
	   {
	   if(mysql_num_rows($result)>1)
	   {
	   $colu="";
	   $sql=mysql_query("SHOW COLUMNS FROM programmes");
if(mysql_num_rows($result)>11)
{
echo '<div style="width:700px; height:400px; overflow-Y:scroll; ">';
}
      echo '<table border="1" class="tablefontv">';
	  echo "<tr bgcolor='#6AB5FF'>";
	while($rowc=mysql_fetch_row($sql))
  {
  if(empty($colu))
  {
  $colu=$rowc[0];
  }
  else
  {
   $colu=$colu.",".$rowc[0];
  }
  if($rowc[0]=="School_Id")
  {
    echo "<td>School Name</td>";
  }
  else
  {
  echo "<td>".str_replace("_"," ",$rowc[0])."</td>";
  }
  }
  echo "</tr>";
 $columns=explode(",",$colu);
        while($row=mysql_fetch_array($result))
  {
 echo "<tr bgcolor='#999999'>";
  for($cv=0;$cv<mysql_num_rows($sql);$cv++)
	{
	 $col_name=$columns[$cv];
	 if($col_name=="School_Id")
	 {
	  $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$row[$col_name]."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
$Name=$rs['Name'];
}
 echo "<td>".$Name."</td>";
	 }
	 else
	 {
	    echo "<td>".$row[$col_name]."</td>";
		}
	}
	  echo '</tr>';
	}
	echo '</table>';
if(mysql_num_rows($result)>11)
{
echo '</div>';
}
	   }
	   if(mysql_num_rows($result)==1)
	   {
	    echo '<table width="458" border="0" class="tablefontv">';
 while($row=mysql_fetch_array($result))
  {
    $Programme_Id=$row['Programme_Id'];
  $res=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Programme_Id'");
  if($rowp=mysql_fetch_array($res))
  {
  $p_name=$rowp['Programme_Name'];
  }
$no_m_stu=$row['No_Of_Male_Students'];
$no_f_stu=$row['No_Of_Female_Students'];
$te_in_trai=$row['Teachers_In_Training'];
$tra_tea=$row['Trained_Teachers'];
$Ava_books=$row['Availability_Books'];
    $Ava_T_Gui=$row['Availability_Tguides'];
     $School_Id=$row['School_Id'];

    $get_Sch_name=mysql_query("SELECT * FROM school WHERE School_Id='".$School_Id."'");
if($rs=mysql_fetch_array($get_Sch_name))
{
$School_Name=$rs['Name'];
}

 	    $year=$row['Year'];
      echo '<tr>';
        echo '<th width="200" height="44" scope="row" bgcolor="#0054A8">';
		echo "Programme Id:";
		echo '</th>';
        echo '<td width="144" bgcolor="#6AB5FF">';
	echo "<input type='text' name='Programme_Id' value='$Programme_Id' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
	    echo '<tr>';
        echo '<th width="200" height="44" scope="row" bgcolor="#0054A8">';
		echo "Programme Name:";
		echo '</th>';
        echo '<td width="144" bgcolor="#6AB5FF">';
	echo "<input type='text' name='Programme_Name' value='$p_name' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
	  	  echo '<tr>';
        echo '<th width="200" height="44" scope="row" bgcolor="#0054A8">';
		echo "School Name:";
		echo '</th>';
        echo '<td width="144" bgcolor="#6AB5FF">';
	echo "<input type='text' name='School_Id' value='$School_Name' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
	   echo '<tr>';
        echo '<th width="200" height="44" scope="row" bgcolor="#0054A8">';
		echo "Year:";
		echo '</th>';
        echo '<td width="144" bgcolor="#6AB5FF">';
	echo "<input type='text' name='Year' value='$year' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row" bgcolor="#0054A8">';
		echo "Number of male students:";
		echo '</th>';
        echo '<td bgcolor="#6AB5FF">';
		echo "<input type='text' name='No_Of_Students' value='$no_m_stu' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
	   echo '<tr>';
        echo '<th height="44" scope="row" bgcolor="#0054A8">';
		echo "Number of female students:";
		echo '</th>';
        echo '<td bgcolor="#6AB5FF">';
		echo "<input type='text' name='No_Of_Students' value='$no_f_stu' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row" bgcolor="#0054A8">';
		echo "Number of teachers in training:";
		echo '</th>';
        echo '<td bgcolor="#6AB5FF">';
		echo "<input type='text' name='Teachers_In_Training' value='$te_in_trai' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row" bgcolor="#0054A8">';
		echo "Number of trained teachers :";
		echo '</th>';
       echo '<td bgcolor="#6AB5FF">';
	  
	echo "<input type='text' name='Trained_Teachers' value='$tra_tea' readonly='readonly'>";
	   echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row" bgcolor="#0054A8">';
		echo "Availability of books:"; 
		echo '</th>';
        echo '<td bgcolor="#6AB5FF">';
		echo "<input type='text' name='Availability_Books' value='$Ava_books' readonly='readonly'>";
            
        echo '</td>';
      echo '</tr>';
      echo '<tr>';
        echo '<th height="44" scope="row" bgcolor="#0054A8">';
		echo "Availability of teachers guides:"; 
		echo '</th>';
        echo '<td bgcolor="#6AB5FF">';
		echo "<input type='text' name='Availability_Tguides' value='$Ava_T_Gui' readonly='readonly'>";
		echo '</td>';
      echo '</tr>';
  }
    echo '</table>';
	}
	}
	if($result)
{
$Exc_quer=str_replace("'","@",$Exc_que);
echo "<form action='../exportreport.php' method='post'><input type='submit' name='ToExcel' class='print' value=''/><input type='hidden' value='$Exc_quer' name='query'/><input type='hidden' value='prorammes' name='Exc_table_name'/></form>";
}
   ?>
</div>
</div>
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">PROGRAMMES</h2>
            </div>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
?>
<?php
}
	  
	   ?>
</body>
</html>